import { Controller } from "egg";


export default class TemplateController extends Controller {

  doPreset() {
    this.service.template.template.preset()
    this.ctx.body = {
      msg: 'ok'
    }
  }

  async list() {
    const { query } = this.ctx.validateReq('template.list')
    const data = await this.service.template.template.list(query.page, query.pageSize)
    this.ctx.success({
      data
    })
  }

  async pageTplDetail() {
    const { query } = this.ctx.validateReq('template.editor')

    const solution = await this.service.template.template.detailDev(query.tplId, query.pageId)
    // console.log(solution)
    this.ctx.success({
      data: solution
    })
  }

  async saveTemplateView() {
    const { body } = this.ctx.validateReq('template.save.view')
    const data = await this.service.template.template.createTemplateView(body.tpl)
    this.ctx.success({
      data
    })
  }

  async publishTemplateView() {
    const { query } = this.ctx.validateReq('template.publish')
    const data = await this.service.template.template.publishTemplateView(query.tplId, query.pageId)
    this.ctx.success({
      data
    })

  }
}